package com.atguigu.gulimall.product.common;

import com.alibaba.nacos.common.utils.StringUtils;
import lombok.extern.slf4j.Slf4j;

import java.lang.reflect.Field;

/**
 * <p>
 *
 * <p>
 *
 * @author lichen
 * @date 2020/11/3 18:12
 */
@Slf4j
public class ObjectUtilsAll {
    private ObjectUtilsAll() {
    }

    /**
     * 判断类中每个属性是否都为空
     *
     * @param object
     * @return
     */
    public static boolean allFieldIsNULL(Object object){
        if (null == object) {
            return true;
        }

        try {
            for (Field f : object.getClass().getDeclaredFields()) {
                if ("serialVersionUID".equals(f.getName()))
                    continue;
                f.setAccessible(true);

                System.out.print(f.getName() + ":");
                System.out.println(f.get(object));

                if (f.get(object) != null && StringUtils.isNotBlank(f.get(object).toString())) {
                    return false;
                }

            }
        } catch (Exception e) {
            e.printStackTrace();
        }

        return true;
    }
}
